<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.8.0">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">




  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2">





















<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=7.0.1">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.0.1">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.0.1">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.0.1">


  <link rel="mask-icon" href="/images/logo.svg?v=7.0.1" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.0.1',
    sidebar: {"position":"left","width":300,"display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: true,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="矩阵求导术参考来源：知乎（长驱鬼侠）：矩阵求导术 注：小写字母表示标量，粗体小写字母表示（列）向量，大写字母表示矩阵。 标量对矩阵的求导矩阵导数和微分建立联系：  df=\sum_{i=1}^m \sum_{j=1}^n \frac{\partial f}{\partial X_{ij} }dX_{ij} = tr( \frac{\partial f}{\partial X}^T dX )该公式第">
<meta name="keywords" content="线性代数">
<meta property="og:type" content="article">
<meta property="og:title" content="矩阵求导术">
<meta property="og:url" content="https://duolk.gitee.io/2019/04/24/矩阵求导术/index.html">
<meta property="og:site_name" content="朝花夕拾">
<meta property="og:description" content="矩阵求导术参考来源：知乎（长驱鬼侠）：矩阵求导术 注：小写字母表示标量，粗体小写字母表示（列）向量，大写字母表示矩阵。 标量对矩阵的求导矩阵导数和微分建立联系：  df=\sum_{i=1}^m \sum_{j=1}^n \frac{\partial f}{\partial X_{ij} }dX_{ij} = tr( \frac{\partial f}{\partial X}^T dX )该公式第">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-04-24T02:51:16.395Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="矩阵求导术">
<meta name="twitter:description" content="矩阵求导术参考来源：知乎（长驱鬼侠）：矩阵求导术 注：小写字母表示标量，粗体小写字母表示（列）向量，大写字母表示矩阵。 标量对矩阵的求导矩阵导数和微分建立联系：  df=\sum_{i=1}^m \sum_{j=1}^n \frac{\partial f}{\partial X_{ij} }dX_{ij} = tr( \frac{\partial f}{\partial X}^T dX )该公式第">



  <link rel="alternate" href="/atom.xml" title="朝花夕拾" type="application/atom+xml">




  <link rel="canonical" href="https://duolk.gitee.io/2019/04/24/矩阵求导术/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>矩阵求导术 | 朝花夕拾</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript><!-- hexo-inject:begin --><!-- hexo-inject:end -->

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">朝花夕拾</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>

      
      
    </ul>
  

  

  
</nav>



  



</div>
    </header>

    
  
  
  
  

  

  <a href="https://github.com/duolk" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewbox="0 0 250 250" style="fill: #222; color: #fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a>



    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://duolk.gitee.io/2019/04/24/矩阵求导术/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="风絮">
      <meta itemprop="description" content="柴门闻犬吠，风雪夜归人">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朝花夕拾">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">矩阵求导术

              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-04-24 10:12:23 / 修改时间：10:51:16" itemprop="dateCreated datePublished" datetime="2019-04-24T10:12:23+08:00">2019-04-24</time>
            

            
              

              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/知识科普/" itemprop="url" rel="index"><span itemprop="name">知识科普</span></a></span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/hint.css/2.4.1/hint.min.css"><h1 id="矩阵求导术"><a href="#矩阵求导术" class="headerlink" title="矩阵求导术"></a>矩阵求导术</h1><p>参考来源：<a href="https://zhuanlan.zhihu.com/p/24709748" title="矩阵求导术" target="_blank" rel="noopener">知乎（长驱鬼侠）：矩阵求导术</a></p>
<p>注：小写字母表示标量，粗体小写字母表示（列）向量，大写字母表示矩阵。</p>
<h2 id="标量对矩阵的求导"><a href="#标量对矩阵的求导" class="headerlink" title="标量对矩阵的求导"></a>标量对矩阵的求导</h2><p>矩阵导数和微分建立联系：</p>
<script type="math/tex; mode=display">
df=\sum_{i=1}^m \sum_{j=1}^n \frac{\partial f}{\partial X_{ij} }dX_{ij} = tr( \frac{\partial f}{\partial X}^T dX )</script><p>该公式第一个等号为全微分公式；</p>
<p>第二个等号为矩阵导数和微分的联系：全微分$df$是导数$\frac{\partial f}{\partial X} (m\times n )$ 与微分矩阵$dX(m\times n)$的内积。</p>
<blockquote>
<p>若标量函数$f$是矩阵$X$经加减乘法、逆、行列式、逐元素函数等运算构成，则使用相应的运算法则对$f$求微分，再使用迹技巧给$df$套上迹并将其他项交换至$dx$左侧，对照导数和微分的联系，就能得到导数。</p>
<script type="math/tex; mode=display">
df = tr( \frac{\partial f}{\partial X}^T dX )</script></blockquote>
<p>其中，加减乘法、逆、行列式、逐元素函数等运算对应的求导法则如下：</p>
<ol>
<li><p>加减法：$d(X\pm Y)=dX\pm dY$；矩阵乘法：$d(XY)=(dX)Y+XdY$；转置：$d(X^T)=(dX)^T$；迹：$dtr(X)=tr(dX)$。</p>
</li>
<li><p>逆：$dX^{-1}=-X^{-1}dXX^{-1}$</p>
</li>
<li><p>行列式：$d\begin{vmatrix} X \end{vmatrix}=tr(X^{*}dX)$，$X^*  $表示伴随矩阵，在X可逆时又可以写作$d\begin{vmatrix} X \end{vmatrix}=\begin{vmatrix} X \end{vmatrix}tr(X^{-1}dX)$。</p>
</li>
<li><p>逐元素乘法：$d(X\odot Y)=dX\odot Y+X\odot dY$，$\odot$表示尺寸相同的矩阵逐元素相乘。</p>
</li>
<li><p>逐元素函数：$d\sigma(X)=\sigma’(X)\odot dX $，$\sigma(X)=[\sigma(X_{ij})]$是逐元素标量函数运算，$\sigma’(X)=[\sigma’(X_{ij})]$是逐元素求导数。</p>
</li>
</ol>
<p>迹技巧如下：</p>
<ol>
<li><p>标量套上迹：$a=tr(a)$</p>
</li>
<li><p>转置：$tr(A^T)=tr(A)$</p>
</li>
<li><p>线性：$tr(A \pm B)=tr(A)\pm tr(B)$</p>
</li>
<li><p>矩阵乘法交换：$tr(AB)=tr(BA)$，其中$A$和$B^T$尺寸相同。</p>
</li>
<li><p>矩阵乘法/逐元素乘法交换：$tr(A^T(B\odot C))=tr((A\odot B)^TC)$，其中$A,B,C$尺寸相同。</p>
</li>
</ol>
<p>链式法则：已求得$\frac{\partial f}{\partial Y}$，而$Y$是$X$的函数，求$\frac{\partial f}{\partial X}$。</p>
<p>先写出$df = tr( \frac{\partial f}{\partial Y}^T dY )$，再将$dY$用$dX$表示出来带入，使用迹技巧将其他项交换至$dX$左侧，即可得到$\frac{\partial f}{\partial X}$。</p>
<script type="math/tex; mode=display">
Y=A \times B \\
df=tr( \frac{\partial f}{\partial Y}^T dY )=tr( \frac{\partial f}{\partial Y}^T AdXB )=tr(B \frac{\partial f}{\partial Y}^T AdX )=tr((A^T \frac{\partial f}{\partial Y} B^T)^TdX ) \\

\frac {\partial f}{\partial X} = A^T \frac{\partial f}{\partial Y} B^T</script><h2 id="矩阵对矩阵的求导"><a href="#矩阵对矩阵的求导" class="headerlink" title="矩阵对矩阵的求导"></a>矩阵对矩阵的求导</h2>
      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/线性代数/" rel="tag"><i class="fa fa-tag"></i> 线性代数</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/04/15/解决win10搜索栏一片空白问题/" rel="next" title="解决win10搜索栏一片空白问题">
                <i class="fa fa-chevron-left"></i> 解决win10搜索栏一片空白问题
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.png" alt="风絮">
            
              <p class="site-author-name" itemprop="name">风絮</p>
              <div class="site-description motion-element" itemprop="description">柴门闻犬吠，风雪夜归人</div>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">10</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  
                    
                      <a href="/categories/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">5</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  
                    
                      <a href="/tags/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">10</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://github.com/duolk" title="GitHub &rarr; https://github.com/duolk" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
            </div>
          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#矩阵求导术"><span class="nav-number">1.</span> <span class="nav-text">矩阵求导术</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#标量对矩阵的求导"><span class="nav-number">1.1.</span> <span class="nav-text">标量对矩阵的求导</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#矩阵对矩阵的求导"><span class="nav-number">1.2.</span> <span class="nav-text">矩阵对矩阵的求导</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">风絮</span>

  

  
</div>









        








        
      </div>
    </footer>

    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/src/utils.js?v=7.0.1"></script>

  <script src="/js/src/motion.js?v=7.0.1"></script>



  
  


  <script src="/js/src/affix.js?v=7.0.1"></script>

  <script src="/js/src/schemes/pisces.js?v=7.0.1"></script>



  
  <script src="/js/src/scrollspy.js?v=7.0.1"></script>
<script src="/js/src/post-details.js?v=7.0.1"></script>



  


  <script src="/js/src/next-boot.js?v=7.0.1"></script>


  

  

  

  



  




  

  

  
  

  
  

  
    
      <script type="text/x-mathjax-config">
  

  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$', '$'], ['\\(', '\\)'] ],
      processEscapes: true,
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
      
      equationNumbers: {
        autoNumber: 'AMS'
      }
    }
  });
  MathJax.Hub.Register.StartupHook('TeX Jax Ready', function() {
    MathJax.InputJax.TeX.prefilterHooks.Add(function(data) {
      if (data.display) {
        var next = data.script.nextSibling;
        while (next && next.nodeName.toLowerCase() === '#text') { next = next.nextSibling }
        if (next && next.nodeName.toLowerCase() === 'br') { next.parentNode.removeChild(next) }
      }
    });
  });
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for (i = 0; i < all.length; i += 1) {
      document.getElementById(all[i].inputID + '-Frame').parentNode.className += ' has-jax';
    }
  });
</script>
<script src="//cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

    
  


  

  

  

  

  

  

  

  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":true},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script><!-- hexo-inject:begin --><!-- hexo-inject:end --></body>
</html>
